package org.ddevil.data.util;

import java.io.Serializable;
import java.util.Iterator;

import org.ddevil.data.Data;
import org.ddevil.data.set.DataSet;

/**
 * @author Rich O'Connell
 */
public class DataSetIterator<T extends Data> implements Iterator<T>, Serializable{
	private static final long serialVersionUID = -1242450707415399305L;

	private DataSet<T> data;
	private int current = -1;

	/**
	 * @param data
	 */
	public DataSetIterator(DataSet<T> data) {
		this.data = data;
	}

	public boolean hasNext() {
		return current < data.size() - 1;
	}

	public T next() {
		current++;
		return data.exportRecord(current);
	}

	/**
	 * XXX buyer beware, untested
	 */
	public void remove() {
		if (current < 0) {
			throw new IllegalStateException("No record to remove.");
		}
		data.removeRecord(current);
		current--;

	}

}
